/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.test;

import java.sql.*;
import java.net.*;
import java.io.InputStream;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Properties;

/**
 * dotProoject database connection class
 * @author K.M.L Sureshika
 * dotProject Summary Portlet for Jefe (http://www.jefesolutions.com)
 * GNU License Version3
 */
public class dotprojectdbconnector {
     //DB connection variables.
    private String dpdbURL;
    private String dpdbName;
    private String dpdbDriver;
    private String dpdbUserName;
    private String dpdbPassword;
    private Connection dpdbConnection;



    //Method to connect to the dotProject database.
    public boolean connectdotProjectDB(URL url)
    {
        boolean dbConnected = false;
                try
        {
        InputStream in = url.openStream();
        Properties p = new Properties();
        p.load( in );

        dpdbURL = p.getProperty("url");
        dpdbName = p.getProperty("database");
        dpdbDriver = p.getProperty("driverClassName");
        dpdbUserName = p.getProperty("username");
        dpdbPassword = p.getProperty("password");
        }
        catch(Exception e) {
            System.out.println("Error :Admin.properties file is not found");
            e.printStackTrace();
        }

        try
        {
            Class.forName(dpdbDriver);
            try{
             dpdbConnection = (Connection) DriverManager.getConnection(dpdbURL+dpdbName,dpdbUserName,dpdbPassword);

             }
             catch (SQLException sQLException) {
                  System.out.println("Error establishing connection");
                   }

           
            dbConnected = true;
        }
        catch(Exception e) {
            System.out.println("Error: Not connected to the JIRA database.");
            e.printStackTrace();
        }
        return dbConnected;
    }
















}
